module.exports = function ($scope, $state, $resource, $modal, toaster) {
	$scope.myKeyup = function (e) {
		//IE 编码包含在window.event.keyCode中，Firefox或Safari 包含在event.which中
		var keycode = window.event ? e.keyCode : e.which;
		if (keycode == 13) {
			$scope.loadlist();
		}
	};
	$scope.currentPage = 1;		//当前页码
	$scope.itemsPerPage = 10;	//每页显示几条
	$scope.pageInfo = {};
	//卡列表
	$scope.loadlist = function () {
		var para = {
			'pageNo': $scope.currentPage,
			'pageSize': $scope.itemsPerPage
		}
		angular.extend(para, $scope.pageInfo);
		$resource('/api/as/ggc/activity/list', {}, {}).save(para, function (res) {
			if (res.errcode === 0) {
				$scope.activityList = res.data.results;
				$scope.totalItems = res.data.totalRecord;
			} else {
				toaster.error({ title: '', body: res.errmsg });
			}
		});
	}

    $scope.loadlist();
    
    $scope.create = function () {
        $state.go('app.tourActivityEdit', { 'type': '0' })
    }
    
    $scope.edit = function (activity) {
        $state.go('app.tourActivityEdit', { 'type': '1', id: activity.id})
    }

	//房间信息
	$scope.info = function (activity) {
		var modalInstance = $modal.open({
			template: require('../views/tourActivityInfo.html'),
			controller: 'tourActivityInfo',
			size: 'lg',
			resolve: {
				activity: function () {
					return activity;
				}
			}
		});
		//关闭模态框刷新页面
		modalInstance.result.then(function () {
			$scope.loadlist();
		});
	}

	//删除卡
	$scope.delete = function(activity){
		if(confirm('确认删除此公告吗？') == true){
			$resource('/api/as/ggc/activity/delete', {}, {}).save(activity, function (res) {
				if (res.errcode === 0){
					toaster.success({title: '', body: '删除成功'});
					$scope.loadlist();
				} else {
					toaster.error({title: '', body: res.errmsg});
				}
			});
		}
	}

};